import {Pipe, PipeTransform} from '@angular/core';
import {isPresent} from '../common';

@Pipe({name: 'ellipsis'})
export class EllipsisPipe implements PipeTransform {
    transform(value: string, args: number[]): string {
        let len = isPresent(args[0]) ? args[0] : 10;
        let sub = isPresent(args[1]) ? args[1] : len;
        let temp = value; 
        if (temp.replace(/[^\x00-\xff]/g, '**').length > len) 
            return value.substring(0, sub) + '...';
        return value;

    }
}
